﻿using commonImportPlugin.Configs.Base;
using commonImportPlugin.Configs.Other;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace commonImportPlugin.Config.Else
{
    //
    //  基本
    //
    #region
    /// <summary>
    /// 初始化函数
    /// </summary>
    public class InitConfig :ConfigsBase, IcommonBase
    {
        //
        //    基本配置参数
        //
        #region
        /// <summary>
        /// 项目ID
        /// </summary>
        public string projectId { set; get; }
        /// <summary>
        ///  项目名称
        /// </summary>
        public string projectName { set; get; }
        /// <summary>
        /// 生成成功日志的项
        /// 值为（bankCardId，personId，ssCardId）
        /// 值为空表示不生成
        /// </summary>
        public string createLogItems { set; get; }
        /// <summary>
        /// 解密数据的模式
        /// </summary>
        public string decryptMode { set; get; }
        #endregion

        //
        //    其他
        //
        #region
        private static InitConfig uniqueInstance;
        public void Init()
        {
            InitConfig initConfig = new InitConfig();

            //项目ID
            if (!IsKeyEmpty("ProjectId"))
            {
                initConfig.projectId = configs["ProjectId"];
            }

            //项目名称
            if (!IsKeyEmpty("ProjectName"))
            {
                initConfig.projectName = configs["ProjectName"];
            }

            //成功日志的项
            if (!IsKeyEmpty("CreateLogItems"))
            {
                #region
                string[] items = new string[] { "bankCardId", "personId", "ssCardId" };
                string[] itemsSeperates = configs["CreateLogItems"].Trim('|').Split('|');
                foreach (string item in itemsSeperates)
                {
                    if (!items.Contains(item))
                        throw new Exception(OtherErrors.CreateLogItemsError);
                }
                initConfig.createLogItems = configs["CreateLogItems"].Trim('|');
                #endregion
            }

            //解密模式
            if (!IsKeyEmpty("DecryptMode"))
            {
                string[] items = new string[] { "NYYH23Track" };
                string item = configs["DecryptMode"].Trim();

                if (!items.Contains(item))
                    throw new Exception(OtherErrors.DecryptModeError);

                initConfig.decryptMode = configs["DecryptMode"];
            }

            uniqueInstance = initConfig;
        }
        /// <summary>
        /// 获取配置
        /// </summary>
        /// <returns></returns>
        public static InitConfig GetConfig()
        {
            if (uniqueInstance == null)
            {
                return null;
            }
            return uniqueInstance;
        }

        //如下两参数对于该配置无用到
        public string factory { set; get; }

        public string fileFilterRules { set; get; }
        #endregion

    }  
    #endregion
}
